Overhaul new Explorist code to work with the released firmware. UNIX only
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 6 Mar 2011 22:59:44 +0000 (22:59 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 6 Mar 2011 22:59:44 +0000 (22:59 +0000)
for now.

That'll teach me to trust pre-releases.   Grrr.

gpsbabel/config.h.in
gpsbabel/configure.in
gpsbabel/explorist_ini.c
gpsbabel/explorist_ini.h
gpsbabel/magproto.c

index 393348a853dca9af8a4e817a699323d29150341b..c802019951fe2f90ac76340c7ca1e3d3e10d1cd3 100644 (file)
@@ -30,6 +30,9 @@
 /* Define to 1 if you have the `sleep' function. */
 #undef HAVE_SLEEP
 
+/* Define to 1 if you have the `glob' function. */
+#undef HAVE_GLOB
+
 /* Define to 1 if you have the `uname' function. */
 #undef HAVE_UNAME
 
index 102f4de18d451942a5a5f518779a5e516f319d47..b10eb7c899096966825f51e5b5fa28d568bb4e9d 100644 (file)
@@ -372,7 +372,7 @@ AC_SUBST(DOCDIR)
 # AC_FUNC_STRTOD
 # AC_FUNC_VPRINTF
 # AC_CHECK_FUNCS([atexit floor localtime_r memmove memset pow select sqrt strchr strcspn strdup strerror strncasecmp strrchr strspn strstr strtol strtoul])
-AC_CHECK_FUNCS([nanosleep sleep uname])
+AC_CHECK_FUNCS([nanosleep sleep uname glob])
 
 #
 # Checks for how the system handles va_list
index cc6136e54cc245841b2d569ea07964099b9a936c..accf8d7067835d001d92047040c38e8dd18b5ba3 100644 (file)
@@ -10,32 +10,55 @@ explorist_read_value(const char* section, const char *key) {
   return inifile_readstr(inifile, section, key);
 }
 
-mag_info *
-explorist_ini_get() {
-  mag_info *info = xmalloc(sizeof(mag_info));
+static mag_info *
+explorist_ini_try(const char *path) {
+  mag_info *info = NULL;
+  char *inipath;
   char *s;
 
-  inifile = inifile_init("Geocaches.ini", myname);
-  s = xstrdup(inifile_readstr(inifile, "Geocaches", "GeocachesPath"));
-  s = gstrsub(s, "\\", "/");
-  info->geo_path = s;
-  inifile_done(inifile);
+  xasprintf(&inipath, "%s/%s", path, "APP/Atlas.ini");
+  inifile = inifile_init(inipath, myname);
+  if (!inifile) {
+    xfree (inipath);
+    return NULL;
+  }
 
-  inifile = inifile_init("Tracks.ini", myname);
-  s = xstrdup(inifile_readstr(inifile, "Tracks", "TracksExportPath"));
-  s = gstrsub(s, "\\", "/");
-  info->track_path = xstrappend(s, "/tracks.gpx");;
-  inifile_done(inifile);
+  info = xmalloc(sizeof(mag_info));
+  info->geo_path = NULL;
+  info->track_path = NULL;
+  info->waypoint_path = NULL;
 
-  inifile = inifile_init("Waypoints.ini", myname);
-  s = xstrdup(inifile_readstr(inifile, "Waypoints", "WaypointsPath"));
-  s = gstrsub(s, "\\", "/");
-  info->waypoint_path = xstrappend(s, "/newwaypoints.gpx");
-  inifile_done(inifile);
+  s = xstrdup(inifile_readstr(inifile,  "UGDS", "WpFolder"));
+  if (s) {
+    s = gstrsub(s, "\\", "/");
+    xasprintf(&info->waypoint_path, "%s/%s", path, s);
+  }
+  s = xstrdup(inifile_readstr(inifile,  "UGDS", "GcFolder"));
+  if (s) {
+    s = gstrsub(s, "\\", "/");
+    xasprintf(&info->geo_path, "%s/%s", path, s);
+  }
+  s = xstrdup(inifile_readstr(inifile,  "UGDS", "TrkFolder"));
+  if (s) {
+    s = gstrsub(s, "\\", "/");
+    xasprintf(&info->track_path, "%s/%s", path, s);
+  }
 
+  inifile_done(inifile);
+  xfree (inipath);
   return info;
 }
 
+mag_info *
+explorist_ini_get(const char **dirlist) {
+  mag_info *r = NULL;
+  while (dirlist && *dirlist) {
+    r = explorist_ini_try(*dirlist);
+    if (r) return r;
+  }
+  return r;
+}
+
 void
 explorist_ini_done(mag_info *info) {
   xfree(info->geo_path);
index fce9708061e8ebe363d8c465a2ae85507219e2ca..665b0de3761bd3bf9d3eaacbe60854ebef4d54d0 100644 (file)
@@ -8,5 +8,5 @@ typedef struct {
   char* waypoint_path;
 } mag_info;
 
-mag_info * explorist_ini_get();
+mag_info * explorist_ini_get(const char **directory_list);
 void explorist_ini_done(mag_info *info);
index 5d89110de6de72249f20d4575679bf4250eaba75..5220efcec92b50259648fdee06b0d33f2d6a2a6c 100644 (file)
 #include "gbser.h"
 #include "explorist_ini.h"
 
+#if HAVE_GLOB
+#include <glob.h>
+#endif
+
 static int bitrate = 4800;
 static int wptcmtcnt;
 static int wptcmtcnt_max;
@@ -58,6 +62,7 @@ static int extension_hint;
 // (This has nothing to do with the Explorist 100...600 products.)
 static ff_vecs_t *gpx_vec;
 static mag_info *explorist_info;
+static char ** os_gpx_files(const char *dirname);
 
 /*
  * Magellan's firmware is *horribly* slow to send the next packet after
@@ -108,6 +113,7 @@ static int ignore_unable;
 static waypoint * mag_wptparse(char *);
 typedef char * (cleanse_fn) (char *);
 static cleanse_fn *mag_cleanse;
+static const char ** os_get_magellan_mountpoints();
 
 static icon_mapping_t gps315_icon_table[] = {
        { "a", "filled circle" },
@@ -751,9 +757,12 @@ mag_rd_init_common(const char *portname)
        // We actually do the rd_init() inside read as we may have multiple
        // files that we have to read.
        if (0 == strcmp(portname, "usb:")) {
-               char *vec_opts = NULL;
-               explorist_info = explorist_ini_get();
-               gpx_vec = find_vec("gpx", &vec_opts);
+               const char **dlist = os_get_magellan_mountpoints();
+               explorist_info = explorist_ini_get(dlist);
+               if (explorist_info) {
+                       char *vec_opts = NULL;
+                       gpx_vec = find_vec("gpx", &vec_opts);
+               }
                return;
        }
 
@@ -1211,17 +1220,36 @@ static void
 mag_read(void)
 {
        if (gpx_vec) {
-               gpx_vec->rd_init(explorist_info->track_path);
-               gpx_vec->read();
+               char **f = os_gpx_files(explorist_info->track_path);
+               while (f && *f) {
+                       gpx_vec->rd_init(*f);
+                       gpx_vec->read();
+                       f++;
+                }
+
+               f = os_gpx_files(explorist_info->waypoint_path);
+               while (f && *f) {
+                       gpx_vec->rd_init(*f);
+                       gpx_vec->read();
+                       f++;
+                }
+#if 0
+               f = os_gpx_files(explorist_info->geo_path);
+               while (f && *f) {
+                       gpx_vec->rd_init(*f);
+                       gpx_vec->read();
+                       f++;
+                }
+#endif
                return;
         }
 
        found_done = 0;
         if (global_opts.masked_objective & TRKDATAMASK) {
                  magrxstate = mrs_handoff;
-          if (!is_file) 
+          if (!is_file)
             mag_writemsg("PMGNCMD,TRACK,2");
-          
+
           while (!found_done) {
             mag_readmsg(trkdata);
           }
@@ -1530,6 +1558,35 @@ mag_write(void)
        }
 }
 
+const char ** os_get_magellan_mountpoints()
+{
+#if __APPLE__
+       const char **dlist = xcalloc(2, sizeof *dlist);
+       dlist[0] = xstrdup("/Volumes/Magellan");
+       dlist[1] = NULL;
+       return dlist;
+#else
+       fatal("Not implemented");
+#endif
+}
+
+// My kingdom for container classes and portable tree-walking...
+// Returns a pointer to a static vector that's valid until the next call.
+static char **
+os_gpx_files(const char *dirname)
+{
+#if HAVE_GLOB
+       static glob_t g;
+       char *path;
+       xasprintf(&path, "%s/*.gpx", dirname);
+       glob(path, 0, NULL, &g);
+       xfree(path);
+       return g.gl_pathv;
+#else
+       fatal("Not implemented");
+#endif
+}
+
 /*
  *  This is repeated just so it shows up as separate menu options
  *  for the benefit of GUI wrappers.